package sample;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class SongWordView extends Application {
    int index = 0;
    @Override
    public void start(Stage primaryStage) throws Exception {

        Button button = new Button("button");
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: plum");
        Scene scene = new Scene(anchorPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(1120);
        primaryStage.setHeight(700);
        primaryStage.show();

        Label label = new Label("label01");
        Label label2 = new Label("label02");
        Label label3 = new Label("label03");
        Label label4 = new Label("label04");
        Label label5 = new Label("label05");

        ImageView imageView = new ImageView("file:/home/hankun/project/MusicApplication/image/haizei.jpeg");
        imageView.setFitHeight(300);
        imageView.setPreserveRatio(true);
        ImageView imageView2 = new ImageView("file:/home/hankun/project/MusicApplication/image/libai.jpg");
        imageView2.setPreserveRatio(true);
        imageView2.setFitHeight(300);
        label.setTranslateZ(-50);
        label2.setTranslateZ(-20);

//        ObservableList<String> observableList = FXCollections.observableArrayList();
//        observableList.addAll(Arrays.asList("adfasd","asdfa","rewe"));
//        TableView<String> tableView = new TableView<>(observableList);
//        tableView.setPrefHeight(200);
//        tableView.setPrefWidth(200);

        VBox vBox = new VBox();
        List<Text> list = new LinkedList<>();
        HBox hBox = new HBox();
        hBox.setSpacing(20);
        hBox.getChildren().addAll(label,label2,label3,label4,label5);
        hBox.setAlignment(Pos.CENTER);
        AnchorPane pane = new AnchorPane();
//        AnchorPane.setRightAnchor(tableView,20.0);
        SubScene subScene = new SubScene(pane,1000,500,false,SceneAntialiasing.BALANCED);
        anchorPane.getChildren().addAll(subScene,button);
        subScene.setLayoutX(10);
        subScene.setLayoutY(10);
        AnchorPane.setLeftAnchor(hBox,80.0);
        AnchorPane.setTopAnchor(hBox,100.0);
        pane.getChildren().addAll(hBox,imageView,imageView2,vBox);
        StackPane stackPane = new StackPane();
        for(int i=0;i<10;i++){
            Text text = new Text("test"+i);
            text.setFont(Font.font(20));
            text.setFill(Color.RED);
            list.add(text);
//            StackPane.setMargin(text,new Insets(10));
//            pane.setPadding(new Insets(10));
            text.setTranslateX(800);
            text.setTranslateY(i==0?200:i*20+200);
            pane.getChildren().add(text);

        }

//        AnchorPane.setriAnchor(vBox,20.0);
//        AnchorPane.setRightAnchor(vBox,20.0);
        vBox.setLayoutX(800);
        vBox.setLayoutY(200);
        imageView.setTranslateX(50);
        imageView2.setTranslateX(200);
        imageView2.setTranslateY(100);
        imageView.setTranslateY(100);
        imageView2.setTranslateZ(0);
        imageView.setTranslateZ(50);
//        stackPane.getChildren().addAll(imageView,imageView2);
//        pane.getChildren().add(stackPane);
        PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
//        perspectiveCamera.set
        subScene.setCamera(perspectiveCamera);
        pane.setStyle("-fx-background-color: skyblue");

        int idx = 0;
        button.setOnAction(event -> {
//            for(int i=0;i<10;i++){
//                Text node = (Text)vBox.getChildren().get(i);
//                node.setTranslateX(10);
//                System.out.println(node.getBoundsInLocal().getMinY());
//            }
            pane.getChildren().clear();
            list.remove(idx);
            list.forEach((text -> {
                if(index++ == 0) {
                    text.setTranslateZ(-100);
                    text.setFill(Paint.valueOf("blue"));
                }
                vBox.getChildren().add(text);
            }));
            index = 0;
        });


    }
//    public SubScene returnPane(){
//
//
//        AnchorPane pane = new AnchorPane();
//        SubScene subScene = new SubScene(pane,1000,500,false,SceneAntialiasing.BALANCED);
//    }
}
